package com.jy.modules.cims.buyback.service;

import org.springframework.stereotype.Service;

import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.data.dto.RedemptionCreditDetailDto;

/**
 * 贷款回购删除
 */
@Service("com.jy.modules.cims.buyback.service.BuyBackDeleteService")
public class BuyBackDeleteService extends BuyBackCommonService {

	/**
	 * 删除交易明细，更新债权明细状态
	 */
	public void doDeleteDetail(String transferIds, String creditorStatus, String dealCode) throws Exception {
		if (CimsConstant.CREDIT_STATUS_RED.equals(creditorStatus)) {
			throw new RuntimeException("债权状态为已赎回，不可删除");
		}
		// 更新债权明细状态
		RedemptionCreditDetailDto redemptionCreditDetailDto = new RedemptionCreditDetailDto();
		redemptionCreditDetailDto.setRedemptionStatus(null);// 交易占用
		redemptionCreditDetailDto.setTransferIds(transferIds);
		creditRight.updateCreditDetailStatus(redemptionCreditDetailDto);
		// 删除债权交易明细
		creditRight.deleteTCMmCreditDealDetailByTransferIds(null, transferIds, dealCode);
		//更新批次表
		buyBackDao.updateBatchBuyBack(dealCode);
	}
}
